#!/bin/sh

revision="Navigation activation v0.1.5 (2023-07-23 by Mibonk & MIB-Wiki)"
# use --help for more info

export PATH=:/proc/boot:/sbin:/bin:/usr/bin:/usr/sbin:/net/mmx/bin:/net/mmx/usr/bin:/net/mmx/usr/sbin:/net/mmx/sbin:/net/mmx/mnt/app/armle/bin:/net/mmx/mnt/app/armle/sbin:/net/mmx/mnt/app/armle/usr/bin:/net/mmx/mnt/app/armle/usr/sbin
export LD_LIBRARY_PATH=/net/mmx/mnt/app/root/lib-target:/net/mmx/mnt/eso/lib:/net/mmx/eso/lib:/net/mmx/mnt/app/usr/lib:/net/mmx/mnt/app/armle/lib:/net/mmx/mnt/app/armle/lib/dll:/net/mmx/mnt/app/armle/usr/lib
export IPL_CONFIG_DIR=/etc/eso/production

thisname="$(basename $0)"
thisdir="$(dirname $0)"

if [ -z $LOG ]; then
	. $thisdir/../config/GLOBALS
fi
echo -ne "\n$ME-$thisname---->\n" | $TEE -i -a $LOG

if [ -f $TMP/reboot.mib ]; then
	echo "Reboot running..."
	return 2> /dev/null
fi

if [ "$3" = "-noboot" ]; then
	noboot=$3
else
	noboot=""
fi

MIBCAP=1
. $thisdir/../config/MIBCHECK

if [ ! -z $2 ]; then
VALUE=$2
else
VALUE=0
fi

trap '' 2

	case $1 in

	-a) {

[ -z "$GEM" ] && echo -ne "\033[36m"
echo -ne "Navigation is activated now\n" | $TEE -a $LOG
[ -z "$GEM" ] && echo -ne "\n"
[ -z "$GEM" ] && echo -ne "\033[m"

echo "Nav region selected: $VALUE"
echo -ne "long coding: "
$PERSR 0 4101 2>> $LOG | $TEE -a $LOG 
echo "LC byte_3_Country_Navigation changed"
$PC i:0:0x50180CFF $VALUE 2>> $LOG
echo "SDS Region Flag"
$PC b:0:0xC0020054:9 $VALUE 2>> $LOG
echo "LC byte_24_Navigation_System"
$PC i:0:0x50186004 1 2>> $LOG
echo "enable Navigation in variant_2"
$PC i:0x286f058c:6 1 2>> $LOG
$PC b:0:1 0 2>> $LOG
sleep 1

echo "set variant_1"
. $thisdir/setvariant -var -noboot

[ -z "$noboot" ] && . $thisdir/reboot -t 10

return 2> /dev/null

	};;

	
	-s) {

[ -z "$GEM" ] && echo -ne "\033[36m"
echo -ne "Navigation Status\n\n" | $TEE -a $LOG
[ -z "$GEM" ] && echo -ne "\033[m"
echo -ne "\nCoding: " | $TEE -a $LOG
$PERSR 0 4101 | $TEE -a $LOG

trap 2

return 2> /dev/null

	};;	
	

	# help or unknown parameter ------------------------------
	*) {
		echo ""
		echo $revision
		echo ""
		echo "Usage: "$thisname" [OPTION1] <VALUE> [-noboot]"
		echo ""
		echo "Option 1:"
		echo "        -a 			activated <VALUE>"
		echo "        -s 			status"
		echo "        --help		show this help"
		echo ""
		echo "Option 2:"
		echo "Specify navigation region. EU=1; NAR=2; ..."
		echo ""
		echo "Option 3:"
		echo "        -noboot	no reboot triggered by script"
		echo ""
		echo "This program is free software; you can redistribute it and/or"
		echo "modify it under the terms of the GNU General Public License"
		echo "as published by the Free Software Foundation; either version 2"
		echo "of the License, or (at your option) any later version."
		echo ""
		echo "This program is distributed in the hope that it will be useful,"
		echo "but WITHOUT ANY WARRANTY; without even the implied warranty of"
		echo "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."
		echo "See the GNU General Public License for more details."
		echo ""
		echo "You should have received a copy of the GNU General Public License"
		echo "along with this program; if not, write to the Free Software Foundation,"
		echo "Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA."
		echo ""

	};;

	esac

exit 0
